package com.cn.ant.modules.wechat.service;

import com.cn.ant.common.service.BaseService;
import com.cn.ant.modules.wechat.dao.HuodongEntityMapper;
import com.cn.ant.modules.wechat.dao.PrizeEntityMapper;
import com.cn.ant.modules.wechat.entity.HuodongEntity;
import com.cn.ant.modules.wechat.entity.PrizeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
/**
 * 微信活动Service
 * @author AntDream
 * @version 2015-03-29
 */
@Component
@Transactional(readOnly = true)
public class HuodongEntityService extends BaseService {

	@Autowired
	private HuodongEntityMapper huodongEntityMapper;
    @Autowired
    private PrizeEntityMapper prizeMapper;
	
	public HuodongEntity get(String id) {
		return huodongEntityMapper.get(id);
	}
	
	public List<HuodongEntity> find(Map<String,Object> param) {
        return huodongEntityMapper.query(param);
	}
	
	@Transactional(readOnly = false)
	public void save(HuodongEntity huodongEntity) {
		huodongEntityMapper.insert(huodongEntity);
	}
	
	@Transactional(readOnly = false)
	public void update(HuodongEntity huodongEntity) {
		huodongEntityMapper.update(huodongEntity);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		huodongEntityMapper.delete(id);
	}

    @Transactional(readOnly = false)
    public void addPrize(PrizeEntity prizeEntity) {
        prizeMapper.insert(prizeEntity);
    }

    @Transactional(readOnly = false)
    public void batchAdd(List<PrizeEntity> prizeEntities) {
        //先删除现有的奖项
        if (prizeEntities != null && prizeEntities.size() > 0) {
            prizeMapper.deleteByHid(prizeEntities.get(0).getHid());
            for (PrizeEntity prize : prizeEntities) {
                prizeMapper.insert(prize);
            }
        }
    }

}
